<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var sumOfLeftLeaves = function (root) {
        //先序遍历 同时传递一个isLeft
        let sum = 0
        function preOrder(root, isLeft) {
          if (!root) return null
          if (!root.left && !root.right) {
            if (isLeft) {
              sum += root.val
            }
          }
          preOrder(root.left, true)
          preOrder(root.right, false)
        }
        preOrder(root, false)
        return sum
      }
    </script>
  </body>
</html>
